/**
 * 
 */

/**
 * The set width command, takes a new Width, which is used to set
 * Width after execute is called. The set Width command object
 * is defined by the new Width and the model, and therefore
 * none of the attributes can be reset after the command has been created
 * @author Sophia Soohoo
 *
 */
public class SetWidth extends BrickCommand {

    /**the new width of the brick model*/
    private double newWidth = 0.0;
    
    /**
     * Constructor which sets the new width, the model,
     * and makes a momento
     * @param model     the model
     * @param newWidth  the new width
     */
    public SetWidth(BrickModel model, double newWidth) {
        super.setModel(model);
        super.setMemento(model.makeMemento());
        this.newWidth = newWidth;
    }
    
    /**
     * execute the command
     * @throws	CommandException
     * @catch	BrickException and pass to CommandException
     */
    @Override
    public void execute() throws CommandException {
        try {
			super.getModel().setWidth(newWidth);
		} catch (BrickException e) {
			throw new CommandException(e.getMessage());
		}
    }

    /**
     * @return the newWidth
     */
    public double getNewWidth() {
        return newWidth;
    }

    /* (non-Javadoc)
     * @see Command#toString()
     */
    @Override
    public String toString() {
        return "new width: " + newWidth;
    }

    
}
